package com.atguigu.bean;

import java.util.List;

/**
 * Date:2020/9/12
 * Author:ybc
 * Description:
 */
public class Page<T> {

    //从浏览器获取的当前页的页码
    private String pageNoStr;
    //每页显示的条数
    private Integer pageSize = 4;
    //总记录数
    private Integer totalCount;

    //转换之后的当前页到的页码
    private Integer pageNo;
    //总页数
    private Integer totalPage;
    //分页对应的当前页的其实索引
    private Integer index;
    //分页之后的集合数据
    private List<T> list;
    //动态获取servlet路径以及除了pageNo的请求参数
    private String path;

    public String getPageNoStr() {
        return pageNoStr;
    }

    public void setPageNoStr(String pageNoStr) {
        this.pageNoStr = pageNoStr;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getPageNo() {
        pageNo = 1;
        try {
            pageNo = Integer.parseInt(pageNoStr);
        } catch (NumberFormatException e) {}
        if(pageNo <= 0){
            pageNo = 1;
        }
        if(pageNo > getTotalPage()){
            pageNo = getTotalPage();
        }
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Integer getTotalPage() {
        totalPage = 0;
        if(totalCount % pageSize == 0){
            totalPage = totalCount / pageSize;
        }else{
            totalPage = totalCount / pageSize + 1;
        }
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getIndex() {
        return (getPageNo()-1)*pageSize;
    }

    public void setIndex(Integer index) {
        this.index = index;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }
}
